namespace RivercrabNet
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Runtime.InteropServices;

    public abstract class PaintLineBase
    {
        private Point beginMovePoint = new Point();
        private List<PointValue> beginMoveValue = new List<PointValue>();
        private string bsName = string.Empty;
        private Rivercrab cgInstance;
        private Color lineColor = Color.White;
        private float[] lineStyle;
        private PaintLineType lineType = PaintLineType.Trend;
        private int lineWidth = 1;
        private int moveType;
        private int ownedPanelID = -1;
        private string plName_zh = string.Empty;
        private List<PointValue> pointList = new List<PointValue>();
        private bool selected;
        private Color selectedColor = Color.Red;
        private int zOrder;

        protected PaintLineBase()
        {
        }

        public abstract void BeginMove();
        public abstract void Draw(Graphics g, List<PointValue> pList, Color curColor);
        public void DrawToImage(Graphics g)
        {
            if ((this.CgInstance.SelectedPaintLine != null) && (this.cgInstance.SelectedPaintLine == this))
            {
                this.Draw(g, this.BeginMoveValue, this.LineColor);
            }
            this.Draw(g, this.PointList, this.CurColor);
        }

        public abstract bool Init(Point mp);
        public abstract bool JudgeSelect();
        public abstract double[] LineParam();
        public abstract void Move();

        public Point BeginMovePoint
        {
            get
            {
                return this.beginMovePoint;
            }
            set
            {
                this.beginMovePoint = value;
            }
        }

        public List<PointValue> BeginMoveValue
        {
            get
            {
                return this.beginMoveValue;
            }
            set
            {
                this.beginMoveValue = value;
            }
        }

        public string BsName
        {
            get
            {
                return this.bsName;
            }
            set
            {
                this.bsName = value;
            }
        }

        public Rivercrab CgInstance
        {
            get
            {
                return this.cgInstance;
            }
            set
            {
                this.cgInstance = value;
            }
        }

        public Color CurColor
        {
            get
            {
                if (this.Selected)
                {
                    return this.selectedColor;
                }
                return this.lineColor;
            }
        }

        public Color LineColor
        {
            get
            {
                return this.lineColor;
            }
            set
            {
                this.lineColor = value;
            }
        }

        public float[] LineStyle
        {
            get
            {
                return this.lineStyle;
            }
            set
            {
                this.lineStyle = value;
            }
        }

        public PaintLineType LineType
        {
            get
            {
                return this.lineType;
            }
            set
            {
                this.lineType = value;
            }
        }

        public int LineWidth
        {
            get
            {
                return this.lineWidth;
            }
            set
            {
                this.lineWidth = value;
            }
        }

        public int MoveType
        {
            get
            {
                return this.moveType;
            }
            set
            {
                this.moveType = value;
            }
        }

        public int OwnedPanelID
        {
            get
            {
                return this.ownedPanelID;
            }
            set
            {
                this.ownedPanelID = value;
            }
        }

        public string PlName_zh
        {
            get
            {
                return this.plName_zh;
            }
            set
            {
                this.plName_zh = value;
            }
        }

        public List<PointValue> PointList
        {
            get
            {
                return this.pointList;
            }
            set
            {
                this.pointList = value;
            }
        }

        public bool Selected
        {
            get
            {
                return this.selected;
            }
            set
            {
                this.selected = value;
            }
        }

        public Color SelectedColor
        {
            get
            {
                return this.selectedColor;
            }
            set
            {
                this.selectedColor = value;
            }
        }

        public int ZOrder
        {
            get
            {
                return this.zOrder;
            }
            set
            {
                this.zOrder = value;
            }
        }

        public class PaintLineZOrderCompare : IComparer<PaintLineBase>
        {
            public int Compare(PaintLineBase x, PaintLineBase y)
            {
                return x.ZOrder.CompareTo(y.ZOrder);
            }
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct PointValue
        {
            private int index;
            private string key;
            private double value;
            public PointValue(int index, string key, double value)
            {
                this.index = index;
                this.key = key;
                this.value = value;
            }

            public int Index
            {
                get
                {
                    return this.index;
                }
                set
                {
                    this.index = value;
                }
            }
            public string Key
            {
                get
                {
                    return this.key;
                }
                set
                {
                    this.key = value;
                }
            }
            public double Value
            {
                get
                {
                    return this.value;
                }
                set
                {
                    this.value = value;
                }
            }
        }
    }
}

